
const db=wx.cloud.database()

/*
  // 放大镜功能
  handlePreviewImage(e) {
    // console.log('11');
    const urls = this.GoodsInfo.pics.map(v => v.pics_mid)
    const current = e.currentTarget.dataset.url
    wx.previewImage({
      current, // 当前显示图片的http链接
      urls// 需要预览的图片http链接列表
    })
  },
  // 加入购物车功能
  handleCartAdd() {
    let cart = wx.getStorageSync('cart') || []
    const index = cart.findIndex(v => v.goods_id === this.GoodsInfo.goods_id)
    if (index === -1) {
      this.GoodsInfo.num = 1
      this.GoodsInfo.checked = true
      cart.push(this.GoodsInfo)
    } else {
      cart[index].num++;
    }
    wx.setStorageSync('cart', cart)
    wx.showToast({
      title: '添加成功',
      icon: 'success',
      mask: true
    })
  },
  
      
      
  },
})
 */


//   },


// })

Page({

  data: {
    goods_detail:[],
    cartList:[]
  },

  onLoad: function (e) {
    let that=this
    let {goods_detail} = this.data
    console.log(e);
    db.collection('goodsDetail').where({
      goods_id:parseInt(e.goods_id)
    })
    .get()
    .then(res=>{
      console.log(res);
       that.setData({
         goods_detail:res.data,
         goods_id:e.goods_id
       })
    })
  },
  
  //加入购物车功能
  handleCartAdd() {
    let that=this
    let {cartList}  = this.data
    db.collection('goodsDetail').where({
            goods_id:parseInt(this.data.goods_id)
          })
          .get()
          .then(res=>{
            console.log(res.data);
               db.collection('cartList').add({
               data:{
                 num:1,
                 image:res.data[0].image,
                 goods_id:res.data[0].goods_id,
                 goods_name:res.data[0].goods_name,
                 goods_introduct:res.data[0].goods_introduct,
                 goods_price:res.data[0].goods_price,
                 saleNum:res.data[0].saleNum
               }
             })
          })
          wx.showToast({
            title: '添加成功',
            icon: 'success',
            mask: true
          })
        },
// 点击立即购买跳转到支付页面
handlePay() {
     wx.navigateTo({
            url: '/pages/pay/pay',
          })
        },
    // 放大镜功能
  handlePreviewImage(e) {
    console.log(e);
    let {goods_detail} =this.data
    console.log(goods_detail);
    let index= e.currentTarget.dataset.index
    const current =  goods_detail[0].image[index]
    const urls =  goods_detail[0].image
      // const urls = this.data.goods_detail.image.map(v => v.image)
      // const current = e.currentTarget.dataset.url
      wx.previewImage({
        current, // 当前显示图片的http链接
        urls// 需要预览的图片http链接列表
      })
  },    
})


